import 'package:flutter/material.dart';
import 'package:flutter_architecture_samples_inherited_widget/screens/add_edit_screen.dart';
import 'package:flutter_architecture_samples_inherited_widget/state_container.dart';
import 'package:todos_app_core/todos_app_core.dart';

import '../models.dart';

class DetailsScreen extends StatelessWidget {
  final Todo todo;
  const DetailsScreen({required this.todo, Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final container = StateContainer.of(context);
    return Scaffold(
      appBar: AppBar(
        title: Text(ArchSampleLocalizations.of(context)!.todoDetails),
      ),
      body: Padding(
        padding: EdgeInsets.all(16.0),
        child: ListView(
          children: [
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Padding(
                  padding: EdgeInsets.only(right: 8.0),
                  child: Checkbox(
                    value: todo.complete,
                    key: ArchSampleKeys.detailsTodoItemCheckbox,
                    onChanged: (complete) {
                      container.updateTodo(todo, complete: !todo.complete);
                    },
                  ),
                ),
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Padding(
                          padding: EdgeInsets.only(top: 8.0, bottom: 16.0),
                          child: Text(todo.task,
                              key: ArchSampleKeys.detailsTodoItemTask)),
                      Text(
                        todo.note,
                        key: ArchSampleKeys.detailsTodoItemNote,
                        style: Theme.of(context).textTheme.headlineMedium,
                      )
                    ],
                  ),
                )
              ],
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        tooltip: ArchSampleLocalizations.of(context)?.editTodo,
        child: Icon(Icons.edit),
        onPressed: () {
          Navigator.of(context).push(MaterialPageRoute(builder: (context) {
            return AddEditScreen(
              todo: todo,
              key: ArchSampleKeys.editTodoScreen,
            );
          }));
        },
      ),
    );
  }
}
